package com.example.demo.service.Impl;

import com.example.demo.entity.User;
import com.example.demo.mapperDAO.UserMapper;
import com.example.demo.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public User login(User user) {
        User login = userMapper.login(user); // 根据用户名和密码
        if (login != null) {
            return login;
        }
        throw new RuntimeException("登录失败...");
    }

    @Override
    public User findById(Integer id){
        return userMapper.findById(id);
    }
}
